from flask import Flask,jsonify,request
import json
from config import Config
from db import db1
app = Flask(__name__)
#加载配置文件
app.config.from_object(Config)
#跨域配置
from flask_cors import CORS
CORS(app)
# @app.route('/test')
# def test():
#     sql1 = "insert into test values(0,'页面基本定期')"
#     db1.update(sql1)
#     sql = "select * from test"
#     res = db1.find_all(sql)
#     return jsonify({'list':res})
    # return res


@app.route('/add',methods=['POST','GET'])
def add():
    if request.method=='POST':
        data=request.data
        if data:
            data=json.loads(data)
        else:
            data=request.form
        sql1 = "insert into test values(0,'%s')"%(data['name'])
        db1.update(sql1)
        return jsonify({'code':200})
    else:
        sql = "select * from test"
        res = db1.find_all(sql)
        return jsonify({'list':res})
    # return res

if __name__=="__main__":
    app.run(debug=True)